\documentclass[10pt,a4paper]{article} 

\usepackage{ctex} % 中文支持
\usepackage[top=2.5cm, bottom=2.5cm, left=2.5cm, right=2.5cm]{geometry} % 页边距
\usepackage{amsmath, amssymb} % 数学公式与符号
\usepackage{graphicx}

\usepackage{pythonhighlight}
\usepackage{url} 

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{listings}
\usepackage{color}

% 设置列表的样式
\definecolor{codegreen}{rgb}{0,0.6,0}
\definecolor{codegray}{rgb}{0.5,0.5,0.5}
\definecolor{codepurple}{rgb}{0.58,0,0.82}
\definecolor{backcolour}{rgb}{0.95,0.95,0.92}

\lstdefinestyle{mystyle}{
    backgroundcolor=\color{backcolour},   
    commentstyle=\color{codegreen},
    keywordstyle=\color{magenta},
    numberstyle=\tiny\color{codegray},
    stringstyle=\color{codepurple},
    basicstyle=\ttfamily\footnotesize,
    breakatwhitespace=false,         
    breaklines=true,                 
    captionpos=b,                    
    keepspaces=true,                 
    numbers=left,                    
    numbersep=5pt,                  
    showspaces=false,                
    showstringspaces=false,
    showtabs=false,                  
    tabsize=2
}

\lstset{style=mystyle}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\usepackage{titling}
\setlength{\droptitle}{-2cm}   % This is your set screw

%%文档的题目、作者与日期
\author{五六七 }
\title{一维和二维数据插值的例子 }

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\begin{document}

\maketitle

\begin{abstract}
本文讲解一维插值的例子：一天中的气温变化。二维插值的例子：地形海拔高度。
\end{abstract}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\setcounter{tocdepth}{2}
%\renewcommand\contentsname{目录}
%
%\renewcommand {\baselinestretch} {1.3}\normalsize 
%\tableofcontents 
%\renewcommand {\baselinestretch} {1.0}\normalsize


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{一天的气温变化}

\subsection{问题描述}
%问题 （来自 \cite{ssk}, p221）：
在一天 24 小时中，从零点开始每间隔2小时测得环境温度如下。
$$ 12, 9, 9, 10, 18, 24, 28, 27, 25, 20, 18, 15, 13. $$

分别进行分段线性插值和三次样条插值，并画出插值曲线。

\subsection{画出散点图}
这也是分段线性插值的结果。就是把数据点按折线连接起来。

\begin{center}
\includegraphics[height=7cm, width=12cm]{mme2024-example-7-4-a.png}
\end{center}

使用的程序如下。

\lstinputlisting[language=Python]{mme2024-example-7-4-a.py}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{分段线性插值的函数表达式}

设已知点的坐标为 $(x_0,y_0), (x_1,y_1), \cdots, (x_n,y_n)$. 其中 $x_0<x_1<\cdots<x_n$. 
则过这些点的分段折线函数为

\begin{eqnarray*}
P_1(x) = \frac{x-x_i}{x_{i+1}-x_i} y_{i+1} + \frac{x-x_{i+1}}{x_{i}-x_{i+1}} y_{i},\,\,\, x\in [x_i,x_{i+1}],\,\,\, i=0,1,\cdots,n-1. 
\end{eqnarray*}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{三次样条插值的函数表达式}

%spline = a flexible wood or rubber strip used especially in drawing large curves.
样条 (spline) 是工程制图用的一种细木条或金属条。
样条曲线是经过一系列给定的点的光滑曲线，
\begin{eqnarray*}
S(x) = \Big{\{} S_i(x) = a_ix^3 +b_ix^2 + c_ix +d_i,\,\,\, x\in [x_i,x_{i+1}],\,\,\, i=0,1,\cdots,n-1 \Big{\}}. 
\end{eqnarray*}
三次样条曲线要求这些分段光滑曲线的二阶导数仍是连续的，
因此需要选取适当的系数 $a_i,b_i,c_i,d_i$, 使得
\begin{eqnarray*}
S(x_i) &=& y_i, \hspace{2cm} i = 0,1,\cdots,n, \\
S_i(x_{i+1}) &=& S_{i+1}(x_{i+1}), \hspace{0.6cm}  i = 0,1,\cdots,n-2, \\
S_i'(x_{i+1}) &=& S_{i+1}'(x_{i+1}), \hspace{0.6cm} i = 0,1,\cdots,n-2, \\
S_i''(x_{i+1}) &=& S_{i+1}''(x_{i+1}), \hspace{0.6cm} i = 0,1,\cdots,n-2.
\end{eqnarray*}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{三次样条插值的图示}
三次样条插值函数是分段定义的，每段都是三次多项式。在连接处有相同的一阶导数和二阶导数。

\begin{center}
\includegraphics[height=6cm, width=12cm]{mme2024-example-7-4-c.png}
\end{center}

\lstinputlisting[language=Python]{mme2024-example-7-4-c.py}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{回答问题}

气温数据的分段线性插值与三次样条插值的结果。

\begin{center}
\includegraphics[height=8cm, width=12cm]{mme2024-example-7-4-b.png}
\end{center}

使用一维插值函数计算，并画出分段线性插值和分段三次多项式插值的图像，使用的程序如下。

\lstinputlisting[language=Python]{mme2024-example-7-4-b.py}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\section{海拔高度数据}

\subsection{问题描述}
%（来自\cite{ssk}, p222）
已知平面区域 $0\le x\le 1400$, $0\le y\le 1200$ 的高程数据（单位：米）。求该区域地表面积的近似值，并用插值数据画出该区域的等高线图和三维表面图。数据见文件：Pdata7-5.txt. 

\begin{table}[ht]\centering 
\begin{tabular}{|c||c|c|c|c|c|c|}\hline
$y\backslash x$ & 0 & 100 & 200 & $\cdots$ & 1300 & 1400 \\ \hline \hline
1200 & 1350 & 1370 & 1390  & $\cdots$ &  210 & 150 \\ \hline
1100 & 1370 & 1390 & 1410  & $\cdots$ &  300 & 210 \\ \hline
$\vdots$ & $\vdots$ & $\vdots$  & $\vdots$ & $\vdots$ & $\vdots$ & $\vdots$  \\ \hline
100 & {\color{red}510} &  {\color{red}620}  & 730  & $\cdots$ &  350 & 320 \\ \hline
0 & {\color{red}370} &  {\color{red}470} &  550  & $\cdots$ & 150 & 250 \\ \hline
\end{tabular}
\end{table}

\subsection{二维网格节点插值}

将边长为 100 米的正方形划分成边长为 10 米的100 个正方形，用插值方法求出在每个格点的海拔高度的估计值。

\begin{table}[ht]\centering 
\begin{tabular}{|c||c|c|c|c|c|c|c|c|c|c|c|}\hline
$y\backslash x$ & 0 & 10 & 20 & 30 & 40 & 50 & 60 & 70 & 80 & 90 & 100 \\ \hline \hline
100 & {\color{red}510} &  & &&&&&&  &     & {\color{red}620} \\ \hline
90 &  &  &  &&&&&& & &     \\ \hline
80 &  &    &  &&&&&& &   &  \\ \hline
$\vdots$ &  &    &  &&&&&& &   &  \\ \hline
%70 &  &    &  &&&&&& &   &  \\ \hline
%60 &  &    &  &&&&&& &   &  \\ \hline
%50 &  &    &  &&&&&& &   &  \\ \hline
%40 &  &    &  &&&&&& &   &  \\ \hline
30 &  &    &  &&&&&& &   &  \\ \hline
20 &  &    &  &&&&&& &   &  \\ \hline
10 &  &    &  &&&&&& &   &  \\ \hline
0 & {\color{red}370} &   &  &&&&&&  &  & {\color{red}470} \\ \hline
\end{tabular}
\end{table}

使用二维网格点插值，计算地表总面积约为 4782737 平方米。

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{三维地形图和等高线图}

\begin{center}
\includegraphics[height=8cm, width=12cm]{mme2024-example-7-5-b.png}
\end{center}

\begin{center}
\includegraphics[height=8cm, width=10cm]{mme2024-example-7-5-a.png}
\end{center}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection{三维地形的程序}

使用二维网格点插值、
计算地表面积、
画出等高线、
画出地形图的程序。

\lstinputlisting[language=Python]{mme2024-example-7-5.py}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\subsection*{附录：函数 meshgrid 与曲面画图}

\begin{center}
\includegraphics[height=5cm, width=8cm]{mme2024-example-7-5-c.png}
\end{center}

\lstinputlisting[language=Python]{mme2024-example-7-5-c.py}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\begin{thebibliography}{99}
\bibitem{ssk} 司守奎, 孙玺菁. \emph{Python数学实验与建模}, 科学出版社. 2020年4月第1版.
\bibitem{jiangqiyuan} 姜启源, 谢金星, 叶俊. \emph{数学模型}, 高等教育出版社. 2018年5月第5版.
\bibitem{giordano} [美] Frank R. Giordano, William P. Fox, Steven B. Horton 著, 叶其孝, 姜启源等译. \emph{数学建模（原书第5版）} [A First Course in Mathematical Modeling (Fifth Edition)], 机械工业出版社, 2014年10月第1版. 

\end{thebibliography}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\end{document}






